//
//  GTSignViewController.m
//  GiftTalk
//
//  Created by Wan on 16/3/23.
//  Copyright © 2016年 Wan. All rights reserved.
//

#import "GTSignViewController.h"
#import <AFHTTPSessionManager.h>

@interface GTSignViewController()

@property (nonatomic,strong) AFHTTPSessionManager *manager;
/** webView */
@property (nonatomic,weak) UIWebView *webView;
@end

@implementation GTSignViewController

#pragma mark 懒加载
- (AFHTTPSessionManager *)manager
{
    if (!_manager) {
        _manager = [AFHTTPSessionManager manager];
    }
    return _manager;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setupNav];
    
    [self getUserSignData];
    
    [self getHtmlData];
    
}

- (void)loadView
{
    self.view = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.webView = (UIWebView *)self.view;
}

- (void)setupNav
{
    self.title = @"每日签到";
    self.view.backgroundColor = GTBackgroundColor;
}

#pragma mark - 加载数据
- (void)getHtmlData
{
    self.manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [self.manager GET:@"http://www.liwushuo.com/credit/sign" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSString *htmlStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
//        GTLog(@"%@",htmlStr);
        
        [self.webView loadHTMLString:htmlStr baseURL:nil];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        GTLog(@"%@",error);
    }];
}

- (void)getUserSignData
{
    NSMutableDictionary *param = @{}.mutableCopy;
    param[@"_"] = @(1458812596271);
    
    [self.manager GET:@"http://www.liwushuo.com/api/credit/me" parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        GTLog(@"%@",error);
    }];
    
}

- (void)dealloc
{
    [self.manager invalidateSessionCancelingTasks:YES];
}
@end
